package ucadminlogic

import (
	"context"
	"github.com/zeromicro/go-zero/core/logx"
	"go.uber.org/zap"
	"navi-mumbai/app/rpc/model/pg/usercenter"
	"navi-mumbai/app/rpc/usercenter/internal/svc"
	"navi-mumbai/app/rpc/usercenter/pb"
	"navi-mumbai/common/utils"
	"navi-mumbai/common/xerr"
)

type CreateApkConfigLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewCreateApkConfigLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateApkConfigLogic {
	return &CreateApkConfigLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 创建活动设置
func (l *CreateApkConfigLogic) CreateApkConfig(in *pb.CreateApkConfigReq) (*pb.CreateApkConfigResp, error) {
	defer utils.RecoverPanic()

	uf := usercenter.ApkConfig{
		Version:     in.Version,
		RewardCoins: in.RewardCoins,
		Currency:    in.Currency,
		Enable:      in.Enable,
		Link:        in.Link,
		Picture:     in.Picture,
	}
	l.Logger.Infof("CreateApkConfig. uf : %+v", uf)
	_, err := l.svcCtx.UserApkConfigModel.Insert(l.ctx, &uf)
	if err != nil {
		l.Logger.Errorf("err == ", zap.Error(err))
		return nil, xerr.NewGrpcErrCodeMsg(xerr.DbError, err.Error())
	}
	return &pb.CreateApkConfigResp{}, nil
}
